<?php
include_once("./_common.php");

// 날짜정보
$query_today = date("Y-m-d");
$query_year = substr($query_today,2,2);
$query_month = substr($query_today,5,2);
$query_date = substr($query_today,8,2);

$vi_update_date = $query_year."년 ".$query_month."월 ".$query_date."일";


// 년도
$this_year = date("Y");


// 시간정보
$query_time = date("a:h:i:s");

if (substr($query_time,0,3) == "am:")
{
	$ampm = "오전 ";
}
else if (substr($query_time,0,3) == "pm:")
{
	$ampm = "오후 ";
}

$vi_update_time = $ampm.date("h : i : s");


//파일첨부 처리하기
if ($attachFile1 == "") {
	$upfile1 = "";
}
else {
	//$upfile1 = "vi_file0 = '{$g5[path]}/m/android/file/visit/attach/$attachFile1',";
	$upfile1 = "vi_file0 = '$attachFile1',";
}

if ($attachFile1 == "") {
	$upfile2 = "";
}
else {
	//$upfile2 = "vi_file1 = '{$g5[path]}/m/android/file/visit/attach/$attachFile2',";
	$upfile2 = "vi_file1 = '$attachFile2',";
}


//사인이미지 처리
if ($j_data == "") {
	$signCfrm = "";
}
else {
	$signCfrm = "j_data = '$j_data',";
}


//
$string = "vi_no = '$vi_no',
	vi_date = '$vi_date',
	vi_flag = '$vi_flag',
	vi_name1 = '$vi_name1',
	vi_time = '$vi_time',
	vi_store = '$vi_store',
	vi_name2 = '$vi_name2',
	vi_count = '$vi_count',
	vi_avg = '$vi_avg',
	vi_sales = '$vi_sales',
	vi_event = '$vi_event',
	vi_hall = '$vi_hall',
	vi_sign = '$vi_sign',
	vi_show = '$vi_show',
	vi_cash = '$vi_cash',
	vi_uni = '$vi_uni',
	$upfile1
	$upfile2
	$signCfrm
	vi_content = '$vi_content',
	vi_confirm = '$vi_confirm',
	vi_area = '$vi_area',
	vi_update_date = '$vi_update_date',
	vi_update_time = '$vi_update_time'";


if ($w == "")
{
	$sql = "INSERT
			  INTO visit_record
			   SET $string";
	$rst = sql_query($sql);
}
else if ($w == "u")
{
	$sql = "UPDATE visit_record
			   SET $string
			 WHERE id = '$id'";
	$rst = sql_query($sql);	
}
else if ($w == "d")
{
	$sql = "DELETE
			FROM	visit_record
			WHERE	id = '$id'";
	$rst = sql_query($sql);
}

if ($month_avg != "")
{
	$sql_m = "UPDATE month_avg
				 SET y{$this_year} = '$month_avg'
			   WHERE store_num = '$vi_area'";
	$rst_m = sql_query($sql_m);
}

echo("success");

?>
